package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler;

import com.iwhalecloud.bss.kite.cucc.service.attr.LocalAttrHelper;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.MVProvAIsExistingCentralNodeAttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.impl.AbstractAttrLinkageHandler;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
@AttrHandler(MVProvAIsExistingCentralNodeAttrHandler.class)
public class MVProvAIsExistingCentralNodeAttrLinkHandler extends AbstractAttrLinkageHandler<AttrData> {

    @Override
    public void handle(KiteAttr attr, KiteInst inst, AttrData data) {

    }

    @Override
    public void handleStyle(KiteAttr attr, KiteInst inst, AttrData data) {
        if ("1_0000106".equals(attr.getValue())) {
            LocalAttrHelper.showAndNotNull(inst, "200002849");
            LocalAttrHelper.showForDAndNull(inst, "200002852");
            Optional.ofNullable(inst.getAttr("200002852")).ifPresent(ipProtocolVersionAttr -> {
                if ("1_0000219".equals(ipProtocolVersionAttr.getValue())) {
                    // ipv4
                    LocalAttrHelper.showForDAndNull(inst, "200002854");
                    LocalAttrHelper.hideAndNullable(inst, "200002856");
                }
                else if ("1_0000220".equals(ipProtocolVersionAttr.getValue())) {
                    // ipv6
                    LocalAttrHelper.hideAndNullable(inst, "200002854");
                    LocalAttrHelper.showForDAndNull(inst, "200002856");
                }
                else if ("1_0000221".equals(ipProtocolVersionAttr.getValue())) {
                    // ipv4/v6双栈
                    LocalAttrHelper.showForDAndNull(inst, "200002854","200002856");
                }
            });
        }
        else if ("1_0000107".equals(attr.getValue())) {
            LocalAttrHelper.hideAndNullable(inst, "200002849", "200002852", "200002854", "200002856");
        }
    }
}
